<?php
// $Id: results.tpl.php,v 1.5 2007/10/11 09:51:29 goba Exp $
global $base_url,$language;
  $url = $base_url . '/' . drupal_get_path('module', 'document');
//print_r($language);
//print "<pre>";print_r($items); print"</pre>";
 

?>
	 		<?php 
		$i=0;           
		foreach ($items as $nid){
			my_db_change(1);
			$vid = db_query('SELECT vid FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
			$row = node_load($nid, $vid);
			
		 if ($row->field_doctype['und'][0]['value'] == 'online') {
			$link =  $row->field_docupload['und'][0]['value'];
		 }
		else if($row->field_doctype['und'][0]['value'] == 'download') {
		    $link = $row->field_docupload['und'][0]['uri'];		
		    $wrapper = file_stream_wrapper_get_instance_by_uri($link);
			if($wrapper == true){
				 $pathfile = $wrapper->getDirectoryPath() . "/" . file_uri_target($link);
			}
			$link="'http://cms.tn.gov.in/tncms_latest/$pathfile'";
		}
		if ($row->field_docupload['und'][0]['filesize'] != '0') {
			$kb = ceil($row->field_docupload['und'][0]['filesize']/1024);
			$kbyte= $kb.KB;
			if($kb >1024) { 
				$kb = ceil($kb/1024);
				$kbyte= $kb.MB;
			}
		} my_db_change(0);
		?>
			<div class="res_title_ch" style="">
				 <p><a onclick="return tnportal_window(<?php print $link ?>);" href="javascript:void(0);" >
						<?php echo  ucfirst(t($row->title)) ?>  <img alt="Download Icon" src="http://cms.tn.gov.in/sites/default/files/icons/pdf_icon.gif">
						<span class="kb">
							<span>(<?php print $kbyte?>)</span> 
						</span>		
					</a>
				 </p>
			</div>			
		<?php $i++; } ?>
		<?php if($i == '0'){?>
			 <div class="no_record">No Results Found </div>
		<?php }	?>
	</div>
</div>
	